package com.fwmagic.spark.core.action

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
  * 取前top个
  */
object TopDemo {
    def main(args: Array[String]): Unit = {
        val conf = new SparkConf()
                .setAppName(this.getClass.getSimpleName)
                .setMaster("local[*]")

        val sc = new SparkContext(conf)

        val rdd1: RDD[Int] = sc.makeRDD(1 to 10)

        implicit val sortRules = Ordering[Int].on[Int](-_)

        //默认升序，加上面的隐式转换改为升序
        val tops: Array[Int] = rdd1.top(3)

        println(tops.toBuffer)

        sc.stop()
    }
}
